# $Id$
# Maintainer: Dave Reisner <dreisner@archlinux.org>

pkgname=nawk
pkgver=20121220
pkgrel=3
pkgdesc="The one, true implementation of AWK"
url="https://www.cs.princeton.edu/~bwk/btl.mirror/"
license=('MIT')
arch=('i686' 'x86_64')
options=('!makeflags')
depends=('glibc')
source=("$pkgname-$pkgver.tar.gz::https://www.cs.princeton.edu/~bwk/btl.mirror/awk.tar.gz"
        'manpage-naming.patch')
md5sums=('b74ca7f8f4284fc82ccee6b4e34531d8'
         '8486d387a51fe3b3c9875c4151ad92b4')

prepare() {
  # awk -> nawk
  patch -Np1 <"$srcdir"/manpage-naming.patch

  # create license
  sed -n '/Copyright/,/THIS SOFTWARE\./p' README > LICENSE

  # fix build
  sed -i '/YACC = yacc -d -S/ s|^|#|' makefile
}

build() {
  make "CPPFLAGS=-DHAS_ISBLANK $CPPFLAGS" \
    "LDFLAGS=$LDFLAGS" \
    "CFLAGS=$CFLAGS"
}

package() {
  install -Dm755 a.out "$pkgdir/usr/bin/nawk"
  install -Dm644 awk.1 "$pkgdir/usr/share/man/man1/nawk.1"
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/nawk/LICENSE"
}
